package com.droid.lib.controls.demo.view;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.droid.lib.controls.demo.R;
import com.droid.lib.controls.demo.activity.MainActivity;
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;

/**
 * Created by Administrator on 2016/9/26.
 */
public class ProgressFragment  extends Fragment {
    private Context mContext;
    private Handler handler;
    CircleProgressBar progress1;
    CircleProgressBar progress2;
    CircleProgressBar progressWithArrow;
    CircleProgressBar progressWithoutBg;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mContext=getActivity();
        View view = inflater.inflate(R.layout.fragment_progress, null);
        progress1 = (CircleProgressBar) view.findViewById(R.id.progress1);
        progress2 = (CircleProgressBar)view. findViewById(R.id.progress2);
        progressWithArrow = (CircleProgressBar) view.findViewById(R.id.progressWithArrow);
        progressWithoutBg = (CircleProgressBar)view.findViewById(R.id.progressWithoutBg);

//        progress1.setColorSchemeResources(android.R.color.holo_blue_bright);
        progress2.setColorSchemeResources(android.R.color.holo_green_light,android.R.color.holo_orange_light,android.R.color.holo_red_light);

        progressWithArrow.setColorSchemeResources(android.R.color.holo_orange_light);
        progressWithoutBg.setColorSchemeResources(android.R.color.holo_red_light);

        handler = new Handler();
        for (int i = 0; i < 10; i++) {
            final int finalI = i;
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (finalI * 10 >= 90) {
                        progress1.setVisibility(View.VISIBLE);
                        progress2.setVisibility(View.INVISIBLE);
                    } else {
                        progress2.setProgress(finalI * 10);
                    }
                }
            }, 1000 * (i + 1));
        }

        if(mContext != null){
            ((MainActivity)mContext).getmResideMenu().addIgnoredView(view);
        }
        return  view;
    }
}
